/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.devs.benchmark.topology;

import java.util.List;
import org.devs.benchmark.modeling.CoupledType;
import org.devs.benchmark.modeling.ModelType;

/**
 *
 * @author Alejandro Moreno
 */
public class ClosedMesh extends Mesh {

    public ClosedMesh(String name, int width, int height, Class message) throws Exception {

        super(name, width, height, message);

    }

    public ClosedMesh(String name, int width, int height, Class message, int recursion) throws Exception {

        super(name, width, height, message, recursion);

    }

    @Override
    public void connectNodes(CoupledType coupled, int width) {

        if (coupled.getModels().size() > 0) {

            List<ModelType> models = coupled.getModels();


            for (int i = 0; i < 4; i++) {

                addConnectionToParent(coupled, 0, i, i);
                addConnectionFromParent(coupled, 0, i, i);

            }

            for (int i = 0; i < models.size(); i++) {

                int j = (i + 1);
                if(j%width == 0)
                    j=(j-width);

                addConnection(coupled, i, 1, j, 3);
                addConnection(coupled, j, 3, i, 1);

                int k = ((i + width) % models.size());

                addConnection(coupled, i, 2, k, 0);
                addConnection(coupled, k, 0, i, 2);

            }

        }

    }
}

